import Ember from 'ember';

export default Ember.Controller.extend({
    mainController: Ember.inject.controller('business.mainpage'),
    customerList:Ember.computed('planList',function(){
      let planExeList = this.get('planList');
      let list = new Ember.A();
      if(planExeList){
        planExeList.forEach(function(project){
          let c = Ember.Object.create({
            cid:project.get('plan.customer.id'),
            cname:project.get('plan.customer.name'),
            sortName:pinyinUtil.getFirstLetter(project.get('plan.customer.name')),
          });
          list.pushObject(c);
        });

      }
      return list;
    }),
    staffList:Ember.computed('planList',function(){
      let planExeList = this.get('planList');
      let list = new Ember.A();
      if(planExeList){
        planExeList.forEach(function(project){
          let staff = Ember.Object.create({
            id:project.get('exeStaff.id'),
            name:project.get('exeStaff.name'),
            sortName:pinyinUtil.getFirstLetter(project.get('exeStaff.name')),
          });
          list.pushObject(staff);

        });
          console.log('list:',list);
      }

      return list;
    }),
    actions:{
      //跳转至编辑页
      toDetailPage(plan){
        if(plan){
          let id=plan.get('id');
          this.get("mainController").switchMainPage('servicecheck-detail',{id:id,editMode:"edit"});
        }else{
          this.get("mainController").switchMainPage('servicecheck-detail',{editMode:"add",id:''});
        }
      },
      selectCustomer(customer){
        this.set('customer',customer);
        App.lookup("route:business.mainpage.serviceapplycheck").doQuery();
      },
      selectStaff(staff){
        this.set('staff',staff);
        App.lookup("route:business.mainpage.serviceapplycheck").doQuery();
      },
      changeBeginDateAction(date) {
          //var stamp = this.get("dateService").getLastSecondStampOfDay(date);
          //this.set("warningModel.callTime", stamp);
          //var stamp=this.get("dateService").dateFormat(date,"yyyy-MM-dd");
          this.set("beginDate",date);
      },
      changeEndDateAction(date) {
          //var stamp=this.get("dateService").dateFormat(date,"yyyy-MM-dd");
          console.log("is true",typeof date);
          this.set("endDate",date);
      },
      dpShowAction(e){

      },
    }

});
